package net.wenku8.reader.api

import net.wenku8.reader.entity.ApiResult
import net.wenku8.reader.model.rank.RankList
import net.wenku8.reader.model.book.BookPreviewInfo
import net.wenku8.reader.util.parseXml

class RankApi {


    companion object {
        fun getRankDetail(sort: String, page : Int = 1): ApiResult<ArrayList<BookPreviewInfo>> {
            val map = mapOf(
                "action" to "novellist",
                "sort" to sort,
                "page" to page.toString(),
            )
            val apiResult = Wenku8Connect.request(map)
            if (!ApiResult.isSuccess(apiResult)){
                return ApiResult.fail(apiResult.message)
            }
            val rankList = parseXml(apiResult.data, RankList::class.java)
            val list = rankAsPreview(rankList)
            return ApiResult.success(list)
        }
    }
}